Add initial single-sandbox-executing-at-a-time support for Hypervisor.framework - #1674
Add initial single-sandbox-executing-at-a-time support for Hypervisor.framework#1674syntactically wants to merge 17 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds initial Hypervisor.framework (HVF) support to hyperlight-host on macOS, along with a snapshot ABI/version bump and memory-layout/page-size changes needed for platforms with 16K host pages.
Changes:
- Introduce an HVF
VirtualMachinebackend and macOS-specific build/runtime glue (bindgen + codesigning runner + interrupt handling). - Bump snapshot ABI/goldens versions and update snapshot file metadata/config handling for the new hypervisor tag and ABI.
- Adjust host/guest memory layout assumptions (page size usage, base addresses, alignment) and tune tests to avoid unsupported parallelism on HVF.
Reviewed changes
Copilot reviewed 39 out of 41 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/hyperlight_host/tests/snapshot_goldens/platform.rs | Add HVF hypervisor tag handling in snapshot golden platform selection. |
| src/hyperlight_host/tests/snapshot_goldens/goldens_version.rs | Bump goldens version and set arch-specific compatibility list. |
| src/hyperlight_host/tests/sandbox_host_tests.rs | Serialize/scale down thread-heavy tests under HVF; adjust scratch sizing. |
| src/hyperlight_host/tests/integration_test.rs | Reduce stress-test thread counts under HVF. |
| src/hyperlight_host/src/sandbox/snapshot/tripwires.rs | Bump expected snapshot ABI and update page-size/base-address invariants. |
| src/hyperlight_host/src/sandbox/snapshot/mod.rs | Align snapshot memory to host page size; update tests to use runtime page size. |
| src/hyperlight_host/src/sandbox/snapshot/file/media_types.rs | Bump SNAPSHOT_ABI_VERSION for snapshot memory blob. |
| src/hyperlight_host/src/sandbox/snapshot/file/config.rs | Add HVF hypervisor tag and macOS/aarch64 CPU vendor behavior. |
| src/hyperlight_host/src/sandbox/snapshot/file_tests.rs | Accept hvf annotation/tag in snapshot file tests. |
| src/hyperlight_host/src/sandbox/initialized_multi_use.rs | Use runtime page size in test helpers and overlap calculations. |
| src/hyperlight_host/src/sandbox/file_mapping.rs | Broaden mmap-backed file mapping resource handling to unix. |
| src/hyperlight_host/src/sandbox/config.rs | Enable interrupt retry delay config for HVF as well as Linux hypervisors. |
| src/hyperlight_host/src/mem/shared_mem.rs | Generalize mmap code to unix and switch guard sizing to runtime page size. |
| src/hyperlight_host/src/mem/shared_mem_tests.rs | Update tests to use runtime page size. |
| src/hyperlight_host/src/mem/mgr.rs | Account for host page alignment when locating snapshot PT tail. |
| src/hyperlight_host/src/mem/memory_region.rs | Use vmem page size constants and runtime page size where needed. |
| src/hyperlight_host/src/mem/layout.rs | Move base address to 0x4000; align sizes for mixed guest/host page sizes. |
| src/hyperlight_host/src/hypervisor/virtual_machine/whp.rs | Make register setters require &mut self to match new VM trait. |
| src/hyperlight_host/src/hypervisor/virtual_machine/mshv/x86_64.rs | Make register setters require &mut self to match new VM trait. |
| src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs | Add HVF module/type and selection; extend error enums for HVF sync/errors. |
| src/hyperlight_host/src/hypervisor/virtual_machine/kvm/x86_64.rs | Make register setters require &mut self to match new VM trait. |
| src/hyperlight_host/src/hypervisor/virtual_machine/kvm/aarch64.rs | Make register setters require &mut self to match new VM trait. |
| src/hyperlight_host/src/hypervisor/virtual_machine/hvf/mod.rs | New HVF backend implementing VM lifecycle, memory mapping, and state sync. |
| src/hyperlight_host/src/hypervisor/virtual_machine/hvf/fp_abi.c | C ABI shims for SIMD FP register access not supported in stable Rust FFI. |
| src/hyperlight_host/src/hypervisor/virtual_machine/hvf/bindings.h | Header for bindgen + shim declarations, includes Hypervisor.framework. |
| src/hyperlight_host/src/hypervisor/surrogate_process.rs | Use runtime page size for guard pages in Windows surrogate mapping. |
| src/hyperlight_host/src/hypervisor/mod.rs | Refactor interrupt handle state tracking; add HVF cancel mechanism support. |
| src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs | Switch to new interrupt handle constructors; adjust VM mutability. |
| src/hyperlight_host/src/hypervisor/hyperlight_vm/mod.rs | Route interrupt state through the new state machine in the VM run loop. |
| src/hyperlight_host/src/hypervisor/hyperlight_vm/aarch64.rs | Add HVF VM construction path and HVF interrupt handle wiring. |
| src/hyperlight_host/Cargo.toml | Add hvf feature, bindgen/cc build deps, parking_lot, and default-enable HVF. |
| src/hyperlight_host/build.rs | Generate HVF bindings and compile the C shim; add HVF cfg alias. |
| src/hyperlight_common/src/mem.rs | Remove fixed page-size constants from mem (shifted to vmem). |
| src/hyperlight_common/src/arch/aarch64/layout.rs | Adjust fixed AArch64 addresses to accommodate 16K pages. |
| flake.nix | Add aarch64-darwin target support and adjust tooling availability per platform. |
| flake.lock | Update pinned nixpkgs revision/hash. |
| dev/macos-sign-and-run.sh | Add macOS runner that codesigns binaries with hypervisor entitlement before exec. |
| dev/macos-entitlements.plist | Add com.apple.security.hypervisor entitlement for signed binaries. |
| CHANGELOG.md | Document the snapshot incompatibility caused by the address/layout change. |
| Cargo.lock | Record new dependencies (parking_lot, bindgen, cc) in the lockfile. |
| .cargo/config.toml | Configure macOS Cargo runner to use the codesign wrapper script. |
|
I submitted #1681, which has full surrogate support for parallel VMs. Would you be able to take a look at that before merging this? (Also, your copyright is out of date in several files) |
ludfjig
left a comment
There was a problem hiding this comment.
Looks really good. I haven't reviewed the changes to InterruptHandle yet. Btw do you know if just snapshot-goldens-pull will work on mac once golden snapshto images areadded? I haven't tested it but I think there mgiht some hardcoded stuff there
jsturtevant
left a comment
There was a problem hiding this comment.
Amazing work! We should be able to run this on CI now?
2484dc7 to
1f35d52
Compare
d77b523 to
9f409ec
Compare
The VM errors are already typed errors, and now the |
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Previously, the Linux and WHP interrupt handle implementations used exactly the same logic to update three bits of atomic state, and further interrupt handle implementations would likely need the same. This commit extracts the state machine logic into a single shared implementation used by both interrupt handles. It also refactors `WindowsInterruptHandle` to pull the logic around locking into another separate type, which will be shared with other interrupt handle implementations in the future Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
This commit moves a bunch of code (primarily mmap-based implementations of things) from cfg(target_os = "linux") to cfg(unix), allowing it to compile on MacOS (where it will be useful). It also moves the kvm and mshv package dependencies from cfg(unix) to cfg(target_os = "linux"), so that Cargo does not try (and fail) to build them on MacOS. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
todo: squash: hvf interrupt handle implementation Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
On AArch64, there is no particular reason to expect the page size of the
host to match the page size of the guest, but the host previously used
some constants (`hyperlight_common::mem::{PAGE_SIZE, PAGE_SIZE_USIZE,
PAGE_SHIFT}`) both when computing guest memory layouts and when
constructing host->guest mappings.
This commit removes all the uses of those ambiguous constants, replacing
them with `page_size::get()` when the host page size is needed and
`hyperlight_common::vmem::PAGE_SIZE` when the guest page size is
required. It also makes a few tweaks to remove assumptions that the
page sizes are the same, allowing (at the very least) operation on a
host with 16k pages while allowing guests to continue using 4k pages.
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
These conceptually mutate the state of the guest, so it makes sense that they should take &mut. This is useful for HVF, which stores a copy of the regs when they are set, and in this manner can avoid an extra Rust lock. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
This adds new variants of the existing create_200_sandboxes test that stress-test the behaviour of the hvf code in situations with many more threads than vcpus. It also adjusts one test which relies on the preservation of system register state whose preservation Hyperlight does not guarantee; while that state is preserved on other backends (up to a snapshot restore) it can be lost on hvf if the vcpu is destroyed and recreated. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Other operating systems do not support its use in EL0 Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
On MacOS, communicating with the hypervisor requires that a binary be signed with an "entitlement" `com.apple.security.hypervisor`. This commit adds a script that locally signs and then runs a binary, and configures Cargo to use that script to run tests/exmaples/etc. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
It will be used in hyperlight-host in the Hypervisor.framework implementation. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
It will be used from the hvf code, which needs to return a structured error itself. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
|
@jsturtevant @ludfjig addressed your comments. I pushed granular commits at 6c6a304, but also pushed again the result of --autosquash so that we won't have to wait for CI + re-approval if automatically dismissed if this is approved with no changes. |
No description provided.